package org.ddevil.data;

import java.io.Serializable;

/**
 * This object represents a basic data item, which is pairing of a value with
 * it's tag(database Id).<br>
 * Once a Attribute is created it's database Id can not be changed.
 *
 * @author Eric Lundin
 * @author Rich
 */
public class Attribute implements Serializable {

	private static final long serialVersionUID = -6975088204286180352L;

	/**
	 * The database identifier for this data item.
	 */
	private final String databaseIdentifier;

	/**
	 * The value of this data item.
	 */
	private Object value;

	/**
	 * Create a new Attribute.
     * The dbId value can not be null.
	 *
	 * @param dbId
	 *            The database identifier for this Attribute.
	 * @param value
	 *            The value to map to this database identifier.
	 */
	public Attribute(String dbId, Object value) {
        if(dbId == null){
            throw new IllegalArgumentException("Attribute can not have a null Database Identifier.");
        }
        databaseIdentifier = dbId;
		setValue(value);
	}

	/**
	 * Get this data item's database identifier.
	 *
	 * @return The database identifier.
	 */
	public String getId() {
		return databaseIdentifier;
	}

	/**
	 * Get the value for this Attribute.
	 *
	 * @return Returns the value.
	 */
	public Object getValue() {
		return value;
	}

	/**
	 * Set the value for this Attribute.
	 *
	 * @param value
	 *            The value to set.
	 */
	public void setValue(Object value) {
		this.value = value;
	}

	@Override
	public String toString() {
		return "(" + getId() + ", " + getValue() + ")";
	}
}
